package com.ingesup.caribou.server.readfile;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;

/*
 * Authors : Alexandre, Morgan
 * Class : ReadParameters
 */

public class ReadParameters {
    protected static int  x_begin, x_end, x_step, y_begin, y_end, y_step, max_ampl, aperture;
    
    public void lireFichier(String NomFichier) {
             String chaine;
             int i=0,j=0;
             
             int tab[] = new int[8];
             // lecture du fichier
            try {
              BufferedReader in  = new BufferedReader(new FileReader(NomFichier));
              String str = "";
              while ( (str=in.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(str,"=");
                while(st.hasMoreTokens()) {
                    chaine = st.nextToken();
                    if ( i%2 != 0 ) {
                        tab[j] = Integer.parseInt(chaine);
                        j++;
                    }
                    i++;
                    System.out.println("Element lu = " + chaine);
                }
              }
              in.close();
              
              // affectation des parametres
              x_begin=tab[0];
              x_end=tab[1];
              x_step=tab[2];
              y_begin=tab[3];
              y_end=tab[4];
              y_step=tab[5];
              max_ampl=tab[6];
              aperture=tab[7];
            }
            catch(Exception e){
              e.printStackTrace();
            }
    }
    
    public static String afficher() {
        return ("x_begin = " + x_begin + ", x_end = " + x_end + ", x_step = " + x_step + ", y_begin = " + y_begin + ", y_end = " + y_end + ", y_step = " + y_step + ", max_ampl = " + max_ampl + ", aperture = " + aperture +".");
    }

    public static int getX_begin() {
        return x_begin;
    }

    public static int getX_end() {
        return x_end;
    }

    public static int getX_step() {
        return x_step;
    }

    public static int getY_begin() {
        return y_begin;
    }

    public static int getY_end() {
        return y_end;
    }

    public static int getY_step() {
        return y_step;
    }

    public static int getMax_ampl() {
        return max_ampl;
    }

    public static int getAperture() {
        return aperture;
    }

    // main
    public static void main(String[] args) {
        ReadParameters r = new ReadParameters();
        r.lireFichier("generator.ini");
        System.out.println(afficher());
    }
}